<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>职员添加</title>
		<link rel="stylesheet" href="../layui/css/layui.css" media="all">
		<style>
			.empAddBox{
				margin: 0 auto;
				margin-top: 80px;
				border: solid gainsboro 1px;
				width: 80%;
				padding: 20px;
				height: 60%;
				
			}
		</style>
	</head>
	<body>
		<div class="empAddBox">
			<form class="layui-form layui-form-pane" method="post" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">职员编号</label>
					<div class="layui-input-inline">
						<input type="text" id="employeeCode" name="employeeCode" lay-verify="required" placeholder="请输入职员编号" autocomplete="off"
						 class="layui-input" readonly>
					</div>
					<label class="layui-form-label">职员姓名</label>
					<div class="layui-input-inline">
						<input type="text" id="employeeName" name="employeeName" lay-verify="required" placeholder="请输入职员姓名" autocomplete="off"
						 class="layui-input" readonly>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">基本工资</label>
					<div class="layui-input-inline">
						<input type="text" id="basicWage" name="basicWage" lay-verify="required" placeholder="请输入基本工资" autocomplete="off"
						 class="layui-input">
					</div>
					<label class="layui-form-label">岗位工资</label>
					<div class="layui-input-inline">
						<input type="text" id="stationWage" name="stationWage" lay-verify="required" placeholder="请输入岗位工资" autocomplete="off"
						 class="layui-input">
					</div>
				</div>


				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">津贴</label>
						<div class="layui-input-inline">
							<input type="text" id="allowance" name="allowance" lay-verify="required" placeholder="请输入津贴" autocomplete="off"
							 class="layui-input">
						</div>
						<label class="layui-form-label">日期</label>
						<div class="layui-input-inline">
							<input type="text" lay-verify="required" name="payoffDate" id="date1" placeholder="请选择日期" autocomplete="off" class="layui-input">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo222">确认修改</button>
				</div>
			</form>
			<input type="hidden" name="hidValue" id="hidValue" />
		</div>
		<script src="../layui/layui.js" charset="utf-8"></script>
		<script>
			layui.use(['form', 'laydate', 'jquery', 'table'], function() {
				var form = layui.form,
					layer = layui.layer,
					laydate = layui.laydate;
				var $ = layui.$;
				var wageupdate = JSON.parse($("#hidValue").val());
				// 数据回显
				$("#employeeCode").val(wageupdate.employeeCode);
				$("#employeeName").val(wageupdate.employeeName);
				$("#date1").val(wageupdate.payoffDate);
				$("#basicWage").val(wageupdate.basicWage);
				$("#stationWage").val(wageupdate.stationWage);
				$("#allowance").val(wageupdate.allowance);

				//日期
				laydate.render({
					elem: '#date1',
					// position: 'fixed',
					// zIndex: 99999999,
				});

				//自定义验证规则
				form.verify({
					title: function(value) {
						if (value.length < 5) {
							return '标题至少得5个字符啊';
						}
					},
					content: function(value) {
						layedit.sync(editIndex);
					}
				});


				//监听提交
				form.on('submit(demo222)', function(data) {
					var index = parent.layer.getFrameIndex(window.name);
					$.ajax({
						url: 'http://localhost:9000/application/wageUpdate',
						type: 'post',
						dataType: 'json',
						data: {
							"wid": wageupdate.wid,
							"employeeCode": data.field.employeeCode,
							"employeeName": data.field.employeeName,
							"basicWage": data.field.basicWage,
							"stationWage": data.field.stationWage,
							"allowance": data.field.allowance,
							"payoffDate": data.field.payoffDate,
						},
						success: function(data1) {
							if (data1.code == 0) {
								layer.msg(JSON.stringify(data1.message), {

								});

								setTimeout(function() {
									parent.layer.close(index);
									parent.window.location.reload();
								}, 3000);
							} else {
								layer.msg("职员编号为：" + wageupdate.wid, + "的职员工资条信息更新失败", {

								});

								setTimeout(function() {
									window.location.href = "empwarning.html";
								}, 3000);
							}



						}
					});
					return false;
				});



				//表单取值
				layui.$('#LAY-component-form-getval').on('click', function() {
					var data = form.val('example');
					alert(JSON.stringify(data));
				});

			});
		</script>

	</body>
</html>
